/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.tech15.core.dao;

import java.util.HashMap;
import java.util.Map;

import javacommon.base.BaseHibernateDao;

import org.springframework.stereotype.Repository;

import cn.org.rapid_framework.page.Page;
import cn.org.rapid_framework.page.PageRequest;

import com.tech15.core.model.SysYg;
import com.tech15.core.vo.query.SysYgQuery;

@Repository
public class SysYgDao extends BaseHibernateDao<SysYg,String>{

	public Class getEntityClass() {
		return SysYg.class;
	}
	
	public Page findByPageRequest(PageRequest<Map> pageRequest) {
		//XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
		// [column]为字符串拼接, {column}为使用占位符. 以下为图方便采用sql拼接,适用性能要求不高的应用,使用占位符方式可以优化性能. 
		// [column] 为PageRequest.getFilters()中的key
		String sql = "select t from SysYg t where 1=1 "
				+ "/~ and t.ygbh = '[ygbh]' ~/"
				+ "/~ and t.name like '%[name]%' ~/"
				+ "/~ and t.deptid = '[deptid]' ~/"
				+ "/~ and t.zw = '[zw]' ~/"
				+ "/~ and t.tel = '[tel]' ~/"
				+ "/~ and t.email = '[email]' ~/"
				+ "/~ and t.zt = '[zt]' ~/"
				+ "/~ and t.phone = '[phone]' ~/"
				+ "/~ order by [sortColumns] ~/";
		return pageQuery(sql,pageRequest);
	}
	
	public Page findPage(SysYgQuery query) {
		String sql = "select t.*,t1.name as dataname,t2.deptname as orgInfo,t3.deptname as fcmc from Sys_Yg t " +
				" left join pub_data t1 on t.zt=t1.id " +
				" left join sys_dept t2 on t.deptid=t2.deptid " +
				" left join sys_dept t3 on t.szfc=t3.deptid where 1=1 "
			+ "/~ and t.ygbh like '%[username]%' ~/"
			+ "/~ and t.name like '%[name]%' ~/"
			+ "/~ and t2.deptname like '%[deptname]%' ~/"
			+ "/~ and t3.deptname like '%[fcmc]%' ~/"
			+ "/~ and t.szdd like '%[szdd]%' ~/"
			+ "/~ and (t2.deptname like '%[key]%' or t.zw like '%[key]%' or t.name like '%[key]%' or t.ygbh like '%[key]%' or t.tel like '%[key]%' or t.phone like '%[key]%') ~/"
			+ "/~ and t.deptid = '[deptid]' ~/"
			+ "/~ and t.zw like '%[zw]%' ~/"
			+ "/~ and t.tel = '[tel]' ~/"
			+ "/~ and t.email = '[email]' ~/"
			+ "/~ and t.zt = [zt] ~/"
			+ "/~ and t.phone = '[phone]' ~/"
			+ "/~ order by [sortColumns] ~/";
		Map map = new HashMap();
		map.put("ygbh", "String");
		map.put("name", "String");
		map.put("deptid", "Long");
		map.put("zw", "String");
		map.put("tel", "String");
		map.put("email", "String");
		map.put("zt", "Long");
		map.put("phone", "String");
		map.put("orgInfo", "String");
		map.put("dataname", "String");
		map.put("fcmc", "String");
		map.put("szdd", "String");
		
		return pageSqlQuery(sql,query,map,SysYg.class);
	}
	

	public SysYg getByYgbh(java.lang.String v) {
		return (SysYg) findByProperty("ygbh",v);
	}	
}
